import requests
from lxml import etree
import re
import threading
import time
from tqdm import tqdm

class VOAThread(threading.Thread):
    def __init__(self, page):
        super().__init__()
        self.page = page
    
    def run(self):
        self.get_mp3_links()
    
    def get_mp3_links(self):
        """
        从VOA新闻网站上获取每条新闻mp3的下载链接
        """
        links=[]
        url = f'https://www.51voa.com/VOA_Standard_{self.page}.html'
        res = requests.get(url)
        html = etree.HTML(res.text)
        for j in range(1, 51):
            link = html.xpath(f'//*[@id="righter"]/div[3]/ul/li[{j}]/a/@href')
            if len(link) > 0:
                links.append(link[0])
        print(links)

if __name__ == '__name__':
    for i in tqdm(range(3, 4)):
        cla1=VOAThread(i)
        